<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>销售订单列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->

    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />

    <!--引用div做成的下拉框效果js-->
    <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>
</head>
<body>

<style>
    .imageSites{
        position: absolute;
        left:520px;
        top:49px;
    }
</style>

<div class="container">

    <div class="comm_content">

        <div class="search-box">
            <div style="position:relative">
                <form class="form-inline" id="search_form" onsubmit="return false;">
                    <table>
                        <tbody>
                        <tr>
                            <td>销售单号：<input type="text" class="form-control input-sm w120" name="saleCode" maxlength="20">
                            项目名称：<input type="text" class="form-control input-sm w120" name="saleName" maxlength="30">
                            创建日期：<input class="form-control input-sm w100" id="startDate" name="startDate" value="" readonly="readonly"   type="text" />
                                ～
                                <input class="form-control input-sm w100" id="endDate" name="endDate" value="" readonly="readonly" type="text" " />
                                <button type="button" class="btn btn-default btn-sm" onclick="timeClear1();">清 空</button>
                            </td>
                        </tr>
                        <tr>
                            <td>客户名称：<input type="text" class="form-control input-sm w120" name="companyName" maxlength="20">

                                <span>
                                        部 门：
                                </span>
                                <span style="vertical-align: middle">
                                        <div class="search_option">
                                            <div class="search_option_drop" >
                                                <span id="searchOptions">
                                                    请选择
                                                <font class="imageSites"><img src="/quanliadmin/docroot/images/comm/selects.jpg"></font>
                                                </span>
                                            </div>

                                            <ul class="search_option_panel"  id="searchPanels" style="display: none;z-index: 100;">
                                                <li class="childSelectImg" departmentID="" style="margin-top:5px;margin-bottom:5px;margin-left: 0px;font-size: 13px;" >请选择</li>
                                                <!--{$department_select_html}-->
                                            </ul>

                                            <input type="hidden" value="" id="hdnSearchTypes" name="hdnSearchType">
                                            <input type="hidden" value="" id="search_departmentID" name="search_departmentID">
                                            <!--<input type="hidden" value="" id="departmentName" name="departmentName">-->
                                        </div>
                                    </span>

                                <span>
                                   销售员：<select class="form-control w150" id="userID" name="userID">
                                            <option value="">请选择</option>
                                        </select>
                                </span>
                                <input type="hidden" id="operFlg" value="5">
                                <button type="button" class="btn btn-primary btn-sm" onclick="sale.search();">查 询</button>&nbsp;&nbsp;
                                <button type="button" class="btn btn-warning btn-sm" onclick="sale.clear();">重 置</button>&nbsp;&nbsp;
                                <button type="button" class="btn btn-success btn-sm" onclick="sale.excelout()">导出</button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>

        <table id="flex" style="display:none"></table>

    </div>

</div>

<script type="text/javascript">

    $(function () {
        //日期
        $('#startDate').datepicker();
        $('#endDate').datepicker();

        //绑定列表
        sale.bind();
    })

    //清空日期
    function timeClear1() {
        $('#startDate').val('');
        $('#endDate').val('');
    }

    var sale =
    {
        bind: function ()
        {
            $("#flex").flexigrid({
                url:"/invokingAjax-backend/bill/billSale.ajax?operFlg=1&type=<!--{$type}-->",
                dataType: "json",
                colModel : [
                    {display: "操作", width : 120, align: "center"},
                    {display: "状态", width : 70, align: "center"},
                    {display: "销售单号", width : 150, align : "center"},
                    {display: "项目名称", width : 180,align : "center"},
                    <!--{if !$type}-->{display: "客户名称", width : 180},<!--{/if}-->
                    {display: "联系人", width : 180},
                    {display: "面积", width : 80},
                    {display: "涂装体系", width : 80},
                    {display: "下单时间", width : 150}
                ],
                <!--{if !$type}-->
                buttons : [
                    {name: "添加", bclass: "add", onpress : "sale.add"}
                ],
                <!--{/if}-->
                usepager: true,
                rp: 10,
                useRp: true,
                showTableToggleBtn: true,
                autoload: true
            });
        },

        load: function() {
            $("#flex").flexReload();
        },

        search:function () {
            var dt = $("#search_form").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },

        clear: function() {
            document.getElementById('search_form').reset();
            $("#hdnSearchTypes").val(null);
            $("#search_departmentID").val(null);
            $("#searchOptions").html("请选择 <font class='imageSites'><img src='/quanliadmin/docroot/images/comm/selects.jpg'></font>");
            this.search();
        },

        add: function () {
            E.open("/quanliadmin/app/bill/billSale.pscript?operFlg=2", "", {height: 620,width: 1024, top: 10, left: 150});
        },

        detail: function (code) {
            E.open("/quanliadmin/app/bill/billSale.pscript?operFlg=2&type=<!--{$type}-->&code="+code, "", {height: 620,width: 1024, top: 10, left: 150});
        },

        //导出
        excelout: function (){
            E.confirm('确认导出？',function () {
                $("#operFlg").attr("name", 'operFlg');
                $("#search_form").attr("action", "/invokingAjax-backend/bill/billSale.ajax?operFlg=5");
                $("#search_form").attr("onsubmit", "return true");
                $("#search_form").submit();
                $("#operFlg").attr("name", null);
                $("#search_form").attr("onsubmit", "return false");
            })
        },

        //审核
        audit: function (code) {
            E.confirm('确认审核？',function () {
                E.ajax_post({
                    url : '/invokingAjax-backend/bill/billSale.ajax?operFlg=2',
                    data: {
                        code : code,
                        status : 1
                    },
                    call: function (o) {
                        E.alert(o.message, o.code == 200 ? 2 : 1);
                        sale.load();
                    }
                });
            });
        },

        //取消
        cancel: function (code) {
            E.confirm('确认取消？',function () {
                E.ajax_post({
                    url : '/invokingAjax-backend/bill/billSale.ajax?operFlg=2',
                    data: {
                        code : code,
                        status : 9
                    },
                    call: function (o) {
                        E.alert(o.message, o.code == 200 ? 2 : 1);
                        sale.load();
                    }
                });
            });
        },

        //生产
        product: function (code) {
            E.confirm('确认生产？',function () {
                E.ajax_post({
                    url : '/invokingAjax-backend/bill/billSale.ajax?operFlg=2',
                    data: {
                        code : code,
                        status : 2
                    },
                    call: function (o) {
                        E.alert(o.message, o.code == 200 ? 2 : 1);
                        sale.load();
                    }
                });
            });
        },

    }

    //部门销售人员
    $(window).ready(function() {


        $('#searchPanels').find('li').click(function() {

            var departmentID = $(this).attr('departmentID');
            if (departmentID > 0) {

                E.ajax_get({
                    url: '/invokingAjax-backend/company/company.ajax?operFlg=2',
                    data: {
                        departmentID: departmentID
                    },
                    call: function( o ) {

                        if (o.code == 200) {

                            var html = '<option value="">请选择</option>';
                            if ( o.data ) {
                                $.each( o.data, function( k, v ) {
                                    html += '<option value="' + v.userID + '">' + v.trueName + '</option>';
                                });
                            }
                            $('#userID').html(html);

                        } else {

                            E.alert( o.message);

                        }

                    }
                });

            } else {
                var html = '<option value="">请选择</option>';
                $('#userID').html(html);
            }

        });

    });
</script>

</body>
</html>